/**
 * 
 */
package playGround.dungeon;

import playGround.border.Door;
import playGround.square.Rock;
import playGround.square.Square;
import be.kuleuven.cs.som.annotate.Raw;

/**
 * @author Niels en Maarten
 * @version 2.3
 *
 */
public class Shaft<S extends Square> extends NonCompositeDungeon<S> {

	/**
	 * @param maxDimensions
	 * @effect
	 * 		| super(maxDimensions)
	 */
	@Raw
	public Shaft(Position maxDimensions) {
		super(maxDimensions);
	}
	/**
	 * @param position the position to check
	 * @return
	 * 		| countDirection = 0
	 * 		|if(position.getXValue()==0)
	 * 		|then countDirection++
	 * 		| if(position.getYValue()==0)
	 * 		| then countDirection++
	 * 		| if(position.getZValue()==0)
	 * 		| then countDirection++
	 * 		| if(countDirection != 2 || !super.canHaveAsMaxDimensions(position))
	 * 		| then result == false
	 */
	@Override @Raw
	public boolean canHaveAsMaxDimensions(Position position){
		int countDirection = 0;
		if(position.getXValue()==0)
			countDirection++;
		if(position.getYValue()==0)
			countDirection++;
		if(position.getZValue()==0)
			countDirection++;
		return countDirection==2 && super.canHaveAsMaxDimensions(position);
	}
	/**
	 * @param square the square you want to check
	 * @return 
	 * 		| if(square instanceof Rock || ! super.canHaveAsSquare(square))
	 * 		| then result == false
	 */
	@Override
	public boolean canHaveAsSquare(Square square){
		if(square instanceof Rock)
			return false;
		return super.canHaveAsSquare(square);
	}
	/**
	 * @param square the square you want to resolve
	 * @param position of the square
	 * @post
	 * 		| for each direction in square.getAllBorders().keySet()
	 * 		| Square neighbour=super.getPositionSquares().get(position.getNeighboringPosition(direction))
	 * 		| if( != null)
	 * 		| if(square.getBorder(direction) instanceof Door)
	 * 		| then new.square.getBorder(direction) == null
	 * 		| if(neighbour.getBorder(Direction.getComplement(direction))instanceof Door)
	 * 		| then new.neighbour.getBorder(Direction.getComplement(direction)) == null
	 */
	@Override
	public void resolveBorder(Position position, Square square) {
		for(Direction direction:square.getAllBorders().keySet()){
			Square neighbour=super.getPositionSquares().get(position.getNeighboringPosition(direction));
			if (neighbour!=null){
				if(square.getBorder(direction) instanceof Door)
					square.removeBorder(direction);
				if(neighbour.getBorder(Direction.getComplement(direction))instanceof Door)
					neighbour.removeBorder(Direction.getComplement(direction));
			
			}
		}
	}

	
}
